<html>
    <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
<?php
require_once '../model/db.php';
require_once '../model/keywords.php';
require_once '../model/Works.php';


///$keywords = new Keywords();
//$list_of_keywords = $keywords->lenght();
$keywords = new work();
$list = $keywords->works();
//Code nay tu viet ko vay :p????? khog cung co nguoi chi
//Bo sung:
//Phai them pagination vao class

?>
    <?php 
    $page=1;
    if(isset($_GET['page']))
      $page = $_GET['page'];  
    ?>
    <from method='GET'>
           
        <?php
        $list = $keywords->select($page);
        ?>
           <a href='index.php?page=1'><< Frist</a>
        <a href="index.php?page=<?php echo  $page-1 ?>"><< Prev</a>
      
          <?php
            if ($page <= 3) {
            for ($i = 1; $i <=count($list)-1 ; $i++) {
                ?> 
                <a href='index.php?page=<?php echo $i ?>'><?php echo $i ?></a>
            <?php
            }
        } elseif ($page >= 17) {
            for ($i = 15; $i <= 19; $i++) {
                ?> 
                <a href='index.php?page=<?php echo $i ?>'><?php echo $i ?></a>
            <?php }
        } else {
            for ($i = ($page - 2); $i <= ($page + 2); $i++) {
                ?>
                <a href='index.php?page=<?php echo $i ?>'><?php echo $i ?></a>
        <?php }
    } ?>
        <a href="index.php?page=<?php echo ($page + 1) ?>">Next >></a>
        <a href='index.php?page=19'>Last >></a>

              
        
?>
        </from><br>
        <table>
        <tr>
        <td> Id   </td>
        <td> Posted</td>
        <td> Name </td>
        <td> Upload</td>
        <td> Images</td>
        </tr>
        <?php foreach ($list as $lists):?>
        <tr>
            <td> <?php echo $lists["id"]; ?> </td>
                     
            <td><?php $mydate = getdate($lists["posted"]); ?> 
                 <?php echo "$mydate[mday] $mydate[month], $mydate[year]"; ?>
            </td>
            <td><a href="<?php echo substr($lists["url"],0,50 );?>">
                 <?php echo $lists["name"]; ?></a></td>    
            <td>
                <a href="upload_file.php?id=<?php echo $lists["id"] ;?>">Edit</a>
                <a href="#">View</a>
                <a href="#">Deleted</a>
            </td>
            <td><img src="<?php echo$lists['image'] ?>"</td>
         </tr>
      
       <?php endforeach; ?>
    </table>
   
    </body>
    
</html>
   